from google.appengine.ext import ndb
import logging

class Dic(ndb.Model):
    name = ndb.StringProperty()
    lang = ndb.StringProperty()
    label = ndb.TextProperty()
    cat = ndb.StringProperty()
    
class Operation():
    def getLabel(self, lang, name, cat):
        logging.info("get label:" + lang + "_" + name + "_" + cat)
        dics = Dic.query(Dic.name == name, Dic.cat == cat, Dic.lang == lang).fetch()
        for dic in dics:
            if dic.label:
                return str(dic.label)
            else:
                return name
        
    def getDics(self, lang, cat):
        logging.info("get labels:" + lang + "_" + cat)
        dics = Dic.query(Dic.cat == cat, Dic.lang == lang).fetch()
        return dics
